//
//  KLSGDataFail.m
//  KaoLaShiGuangFM
//
//  Created by lanou3g on 15/11/9.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "KLSGDataFail.h"

@interface KLSGDataFail ()

@property (nonatomic, strong) UIImageView *failImageView;

@property (nonatomic, strong) UILabel *dataFailLabel;
@property (nonatomic, strong) UIButton *dataFailButton;

@end

@implementation KLSGDataFail

// 懒加载
- (UIImageView *)failImageView
{
    if (!_failImageView) {
        _failImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth/2 - 50/2, 10, 50, 50)];
    }
    return _failImageView;
}

- (UILabel *)dataFailLabel
{
    if (!_dataFailLabel) {
        _dataFailLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth/2 - 130/2, 65, 130, 30)];
    }
    return _dataFailLabel;
}

- (UIButton *)dataFailButton
{
    if (!_dataFailButton) {
        _dataFailButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    }
    return _dataFailButton;
}

#pragma mark - 网络请求失败
- (void)netRequestFailWithBlock:(void(^)())failBlock
{
    self.backgroundColor = [UIColor whiteColor];
    self.failImageView.image = [UIImage imageNamed:@"dataFail1"];
    [self addSubview:self.failImageView];
    
    self.dataFailLabel.text = @"木有加载出来...";
    self.dataFailLabel.textColor = [UIColor colorWithRed:234 / 256.0 green:79 / 256.0 blue:56 / 256.0 alpha:1];
    self.dataFailLabel.alpha = 0.7;
    self.dataFailLabel.textAlignment = YES;
    [self addSubview:self.dataFailLabel];

    self.dataFailButton.frame = CGRectMake(kScreenWidth/2 - 100/2, 100, 100, 30);
    [self.dataFailButton setTitle:@"请点击重试" forState:(UIControlStateNormal)];
    [_dataFailButton setTitleColor:[UIColor colorWithRed:234 / 256.0 green:79 / 256.0 blue:56 / 256.0 alpha:1] forState:(UIControlStateNormal)];
    [_dataFailButton.layer setCornerRadius:5.0];
    [_dataFailButton.layer setBorderWidth:1.0];
    _dataFailButton.layer.borderColor = [UIColor colorWithRed:234 / 256.0 green:79 / 256.0 blue:56 / 256.0 alpha:1].CGColor;
    [self.dataFailButton addTarget:self action:@selector(actionDataRequest:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:self.dataFailButton];

    
    self.block = failBlock;
}

- (void)actionDataRequest:(UIButton *)button
{
    self.block();
}

- (void)hidden
{
    [self removeFromSuperview];
}

@end
